/*
 * Hungarian.cpp
 *
 *  Created on: Sep 28, 2012
 *      Author: pedro
 */

#include "Hungarian.h"

Hungarian::Hungarian(Graph &g)
{

	int r[g.getSize()][g.getSize()];

	for(int i = 0; i < g.getSize(); ++i)
	{
		for(int j = 0; j < g.getSize(); ++j)
		{
			r[i][j] = g(i,j);
		}
	}


	hungarian_init(&prob,(int*)r,g.getSize(),g.getSize(),HUNGARIAN_MIN);

}

Hungarian::~Hungarian() {
	  hungarian_fini(&prob);
}

vector<int> Hungarian::solve()
{
	vector<int> s;

	hungarian_solve(&prob);

	//hungarian_print_assignment(&prob);

	for(unsigned int i =0; i < prob.m ; i++)
	{
		for(unsigned int j = 0; j < prob.n; j++)
		{
			if(j == (unsigned int) prob.a[i])
				s.push_back(j);
		}
	}

	return s;
}



